<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%@ include file="../../common/taglib.jsp"%>

<title>大小名单</title>
<head>
<script type="text/javascript" src="/static/js/common.js"></script>
<%@ include file="../../common/public.jsp"%>


<script type="text/javascript">
	//显示插入模态框
	function insertView() {
		$.post("insertView", null, function(data) {
			$("#insert-modal-body").html(data);
		});
	}

	var insertValidate = {
		feedbackIcons : {
			valid : 'glyphicon glyphicon-ok',
			invalid : 'glyphicon glyphicon-remove',
			validating : 'glyphicon glyphicon-refresh'
		},
		fields : {
			pmname : {
				validators : {
					notEmpty : {
						message : "请填写名单名称"
					},
					remote : {
						message : "该名单名称已存在",
						url : 'validatePmname',
						type : 'POST',
						data : function(validator) {
							return {
								pmname : $("input[name='pmname']").val()
							};
						}

					}
				}

			}
		}
	}

	function insert() {

		var bv = $("#insert-form").data('bootstrapValidator');
		bv.validate();
		if (bv.isValid()) {
			$.post("insert", $("#insert-form").serialize(), callback);

		}
	}

	function callback(data) {
		alert(data.Msg);
		if (data.result == "success") {
			queryAllPerson('${pagehelper.pageNum}', '${pagehelper.pageSize}');

		}
	}

	function deleteView(id) {
		$.post("deleteView/" + id, function(data) {
			$("#delete-modal-body").html(data);
		});
	}

	function delById() {
		var id = $("#del-id").val();
		$.post("delete/" + id, callback);
	}

	function updateView(id) {
		$.post("updateView/" + id, function(data) {
			$("#update-modal-body").html(data);
		});
	}

	function update() {

		var bv = $("#update-form").data('bootstrapValidator');
		bv.validate();
		if (bv.isValid()) {
			$.post("update", $("#update-form").serialize(), callback);

		}
	}
</script>
</head>
<body>
	<div class="container">

		<div class="row clearfix">
			<div>
				<%@ include file="../index.jsp"%>
			</div>
			<form action="list" id="form-select" class="form-inline">

				<input type="hidden" id="pageNum" name="pageNum"> <input
					type="hidden" id="pageSize" name="pageSize">

				<div class="form-group">
					名单编号：<input class="form-control" type="text" id="select-pmno-text"
						name="pmno" style="text-align: center; line-height: 18px;"
						placeholder="填写名单名称">
				</div>
				&nbsp;&nbsp;
				<div class="form-group">
					名单名称：<input class="form-control" type="text"
						id="select-pmname-text" name="pmname"
						style="text-align: center; line-height: 18px;"
						placeholder="填写名单名称">
				</div>
				&nbsp;&nbsp;
				<div class="form-group">
					名单类型：<select id="select-pmtype" name="pmtype" class="form-control">
						<option value="">--请选择--</option>
						<option value=1>大名单</option>
						<option value=2>小名单</option>
					</select>
				</div>
				&nbsp;&nbsp;
				<div class="form-group">
					<button class="btn btn-default" style="width: 100px;" type="submit">查询</button>
					<button type="reset" class="btn btn-default" style="width: 100px;">重置</button>
				</div>

			</form>

			<div class="col-md-12">

				<div class="col-md-10">
					<div class="col-md-2">
						<button class="btn btn-default" data-toggle="modal"
							data-target="#insertModal" data-backdrop="static"
							onclick="insertView();">新增</button>
					</div>
				</div>
			</div>

			<table class="table table-hover">
				<thead>
					<tr class="text-center">
						<td>序号</td>
						<td>名单编号</td>
						<td>名单类型</td>
						<td>名单名称</td>
						<td>包含小名单</td>
						<td>总人数</td>
						<td>引用</td>
						<td>设置人</td>
						<td>设置时间</td>
						<td>备注</td>
						<td>操作</td>
					</tr>
				</thead>

				<tbody>
					<c:forEach items="${pagehelper.list}" var="item" varStatus="status">
						<tr class="text-center">
							<td>${status.count}</td>
							<td>${item.pmno}</td>
							<td>${item.pmtype}</td>
							<td>${item.pmname}</td>
							<td><c:choose>
									<c:when test="${empty item.sonsize}">--</c:when>
									<c:when test="${not empty item.sonsize}">${item.sonsize}个</c:when>
								</c:choose></td>
							<td><c:choose>
									<c:when test="${empty item.num}">--</c:when>
									<c:when test="${not empty item.num}">${item.num}人</c:when>
								</c:choose></td>
							<td><c:choose>
									<c:when test="${item.quote eq 0}">
										<span>未引用</span>
									</c:when>
									<c:when test="${item.quote != 0}">
										<button class="btn btn-default" data-toggle="modal"
											data-target="#detailsModal" data-backdrop="static"
											onclick="detail('${item.id}')">已引用</button>
									</c:when>
								</c:choose></td>
							<td>${item.addman}</td>
							<td><fmt:formatDate value="${item.addtime}"
									pattern="yyyy-MM-dd HH:mm:ss" /></td>
							<td>${item.remark}</td>
							<td>
								<button class="btn btn-default" data-toggle="modal"
									data-target="#updateModal" data-backdrop="static"
									onclick="updateView('${item.id}');">编辑</button>
								<button class="btn btn-default" data-toggle="modal"
									data-target="#delModal" data-backdrop="static"
									onclick="deleteView('${item.id}');">删除</button>
							</td>


						</tr>
						</tr>
					</c:forEach>
				</tbody>

			</table>




			<div id="" style="margin-top: 20px;">
				<%@ include file="../../common/pagehelper.jsp"%>
			</div>


		</div>
	</div>

	<%@ include file="../../common/modal.jsp"%>
</body>
</html>